package com.edgar.baselibrary.network.request;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;

import com.edgar.baselibrary.network.response.IResponse;

public class BasicRequest<T> implements IRequest{
	private String mUrl;
    private Map<String,String> mHeadersMap;
    private Map<String,?> mParamsMap;
    private IResponse<T> mResponse;
    private boolean mShouldCache;
    private Object mTag;

    public BasicRequest(String url){
    	this.mUrl = url;
    }

    public BasicRequest(String url,IResponse<T> response){
    	this.mUrl = url;
    	this.mResponse = response;
    }

    public void addHeaders(Map<String,String> headers){
    	ensureHeaderMap();
        if(headers != null && !headers.isEmpty()){
            mHeadersMap.putAll(headers);
        }
    }

    public Map<String, String> getHeaders(){
    	ensureHeaderMap();
    	return mHeadersMap;
    }

    private void ensureHeaderMap(){
    	if(mHeadersMap == null){
    		mHeadersMap = new HashMap<String,String>();
    	}    	
    }

    public void setTag(Object tag){
    	this.mTag = tag;
    }

    public Object getTag(){
    	return mTag;
    }

    public void setShouldCache(boolean shouldCache){
    	this.mShouldCache = shouldCache;
    }

    public boolean getShouldCache(){
    	return mShouldCache;
    }

    /**
     * The call method add request params to http body
     * @param params
     */
    public void setParams(Map<String, Object> params){
    	this.mParamsMap = params;
    }

	public Map<String, ?> getParams(){
		return mParamsMap;
	}

	public String getUrl(){
		return mUrl;
	}

	public final IResponse<T> getResponse(){
		return mResponse;
	}
}